import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class test3 {
    public static void main(String[] args) {
        try (FileReader fileReader = new FileReader("test.txt")) {
            char[] c = new char[20];

            // 读取8个字符，从数组下标2开始存储
            int len = fileReader.read(c, 2, 8);

            System.out.println("读取的字符长度为：" + len);

            if (len != -1) {
                System.out.print("整个数组内容：");
                for (char ch : c) {
                    if (ch == '\u0000') {
                        System.out.print("[null]");
                    } else {
                        System.out.print(ch);
                    }
                }
                System.out.println();

                System.out.print("实际有效内容（下标2开始）：");
                for (int i = 2; i < 2 + len; i++) {
                    System.out.print(c[i]);
                }
            } else {
                System.out.println("文件为空");
            }
        } catch (IOException e) {
            System.out.println("读取文件时出错: " + e.getMessage());
        }
    }
}s